Skip to content

feat: Add azurefunctions-extensions-bindings-kafka for KafkaRecord binding (#155)#156

Open
TsuyoshiUshio wants to merge 1 commit intoAzure:devfrom
TsuyoshiUshio:feature/kafka-record-extension
Open

feat: Add azurefunctions-extensions-bindings-kafka for KafkaRecord binding (#155)#156
TsuyoshiUshio wants to merge 1 commit intoAzure:devfrom
TsuyoshiUshio:feature/kafka-record-extension

Conversation

@TsuyoshiUshio
Copy link
Copy Markdown

Summary

Add azurefunctions-extensions-bindings-kafka package enabling Python users to bind to raw Apache Kafka records (KafkaRecord type) with full metadata access via Protobuf deserialization.

Issue

Fixes #155
Relates to Azure/azure-functions-kafka-extension#612

Changes

New package: azurefunctions-extensions-bindings-kafka/

File Description
kafkaRecord.py KafkaRecord(SdkType) with Protobuf wire format decoder. KafkaHeader, KafkaTimestamp, KafkaTimestampType types
kafkaRecordConverter.py InConverter for kafkaTrigger binding — handles model_binding_data (single) and collection_model_binding_data (batch)
__init__.py Package exports + version
tests/test_kafka_record.py 11 unit tests
samples/kafka_samples_kafkarecord/ Complete sample with function_app.py, host.json, local.settings.json, requirements.txt, README.md
pyproject.toml Package metadata, dependencies: azurefunctions-extensions-base>=1.1.0, protobuf>=4.0.0,<6.0

CI updates:

  • eng/templates/jobs/build.yml — kafka_extension entry
  • eng/templates/official/jobs/build-artifacts.yml — kafka_extension entry
  • eng/templates/official/jobs/unit-tests.yml — KafkaTests job (Python 3.9–3.13)

No changes needed to azure-functions-python-library or azure-functions-python-worker.

Breaking Changes

None. New package — all existing Kafka bindings (str, bytes, KafkaEvent) continue to work.

Testing

$ python -m pytest -q --instafail azurefunctions-extensions-bindings-kafka/tests/
...........
11 passed in 0.22s

User Experience

import azure.functions as func
import azurefunctions.extensions.bindings.kafka as kafka

app = func.FunctionApp()

@app.kafka_trigger(arg_name="record", topic="my-topic",
                   broker_list="%BrokerList%", consumer_group="$Default")
def kafka_trigger(record: kafka.KafkaRecord):
    logging.info(f"Topic: {record.topic}, Partition: {record.partition}")
    logging.info(f"Value: {record.value.decode('utf-8')}")
    for header in record.headers:
        logging.info(f"Header: {header.key} = {header.get_value_as_string()}")

…ecord binding

New package enabling Python users to bind to raw Apache Kafka records with
full metadata access via Protobuf deserialization.

Package structure (follows EventHub pattern):
- kafkaRecord.py: KafkaRecord(SdkType) with Protobuf decoder, KafkaHeader,
  KafkaTimestamp, KafkaTimestampType types
- kafkaRecordConverter.py: InConverter for kafkaTrigger binding, supports
  model_binding_data (single) and collection_model_binding_data (batch)
- 11 unit tests covering full record, null key/value, null leader epoch,
  unknown timestamp type, batch, headers, type annotations
- Sample app with function_app.py, host.json, local.settings.json, README
- CI: Added to build.yml, build-artifacts.yml, unit-tests.yml matrices

No changes needed to python-library or python-worker.

Fixes Azure#155
Relates to Azure/azure-functions-kafka-extension#612

Co-authored-by: Dobby <dobby@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add azurefunctions-extensions-bindings-kafka package for KafkaRecord binding

1 participant